package cn.hengzhu.main_manager.utils;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import cn.hengzhu.main_manager.repository.domain.ManageUser;



/**
 * 用户上下文
 *   其它模块要用
 *    
 * @author Administrator
 *
 */
public class UserContext {

	private static final String LOGIN_USER = "loginUser";

	/**
	 * 把当前登录用户放到Session中
	 * @param loginUser
	 */
	public static void setUser(ManageUser loginUser) {
		Subject currentUser = SecurityUtils.getSubject();
		currentUser.getSession().setAttribute(LOGIN_USER, loginUser);
	}
	
	
	/**
	 * 从Session获取登录用户
	 * @return
	 */
	public static ManageUser getUser() {
		Subject currentUser = SecurityUtils.getSubject();
		return (ManageUser) currentUser.getSession().getAttribute(LOGIN_USER);
	}
	/**
	 * 删除缓存
	 * @return
	 */
	public static ManageUser removeUser() {
		Subject currentUser = SecurityUtils.getSubject();
		return (ManageUser) currentUser.getSession().removeAttribute(LOGIN_USER);
	}
}
